package fun.tan90.device.main.listener;

import fun.tan90.device.event.EventTopic;
import fun.tan90.device.event.model.ClientInitFailure;
import fun.tan90.device.event.model.ClientInitSuccess;
import fun.tan90.device.event.model.ServerInitFailure;
import fun.tan90.device.event.model.ServerInitSuccess;
import lombok.extern.slf4j.Slf4j;
import org.noear.dami.Dami;
import org.noear.solon.annotation.Component;
import org.noear.solon.core.event.AppBeanLoadEndEvent;
import org.noear.solon.core.event.EventListener;

@Slf4j
@Component
public class AppBeanLoadEndEvent2Listener implements EventListener<AppBeanLoadEndEvent> {

    @Override
    public void onEvent(AppBeanLoadEndEvent event) {
        Dami.<ClientInitSuccess, Void>bus().listen(EventTopic.CLIENT_INIT_SUCCESS_TOPIC, listener -> {
            ClientInitSuccess clientInitSuccess = listener.getContent();
            log.info("client init success: {}", clientInitSuccess);
        });
        Dami.<ClientInitFailure, Void>bus().listen(EventTopic.CLIENT_INIT_FAILURE_TOPIC, listener -> {
            ClientInitFailure clientInitFailure = listener.getContent();
            log.info("client init failure: {}", clientInitFailure);
        });

        Dami.<ServerInitSuccess, Void>bus().listen(EventTopic.SERVER_INIT_SUCCESS_TOPIC, listener -> {
            ServerInitSuccess serverInitSuccess = listener.getContent();
            log.info("server init success: {}", serverInitSuccess);
        });
        Dami.<ServerInitFailure, Void>bus().listen(EventTopic.SERVER_INIT_FAILURE_TOPIC, listener -> {
            ServerInitFailure serverInitFailure = listener.getContent();
            log.info("server init failure: {}", serverInitFailure);
        });
    }
}